package cn.edu.nwsuaf.examcenter.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import cn.edu.nwsuaf.examcenter.aop.DataSourceAdvice;
import cn.edu.nwsuaf.examcenter.pojo.Manager;

public class LoginInterceptor implements HandlerInterceptor {
	private Logger log = Logger.getLogger(LoginInterceptor.class);
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}
	
	/****
	 * 请求处理之前调用
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		// TODO Auto-generated method stub
		log.info("登录超时");
		HttpSession session = request.getSession();
		Manager manager = (Manager)session.getAttribute("managers");
		if(manager==null){
			request.getRequestDispatcher("/WEB-INF/common/timeout.jsp").forward(request, response);
			return false;
		}else{
			return true;
		}
	}

}
